// console.log(location.search.split("=")[1]);
// 获取cookie的vipName
// console.log(location.search.split("&")[1].split("=")[1]);
// console.log(location.search.split("&")[0].split("=")[1]);

$(function () {
    let name = location.search.split("=")[1];
    if (name) {
        getData();
    } else {
        location.href = "http://127.0.0.1/test/VIP/login.html";
    }
})

function getData() {
    $.post('./php/getShoppingCart.php', { vipName: getCookie("vipName") }, function (data) {
        let arr = JSON.parse(data);
        console.log(arr)
        let str = "";
        arr.forEach((item, index) => {
            str += `
        <table>
            <!-- 一件商品 -->
            <tbody>
                <tr>
                    <td class="shop-name">
                        <div class="my-shop clearfix">
                            <div class="checkbox">
                                <span></span>
                            </div>
                            <div class="pic">
                                <img src="${item.goodsImg}" alt="">
                            </div>
                            <div class="info">
                                <h3>${item.goodsDesc}</h3>
                            </div>
                        </div>
                    </td>
                    <td class="price">
                        <span>¥</span>
                        <strong>${item.goodsPrice}</strong>
                    </td>
                    <td class="num-td">
                        <div class="l-total">${item.goodsPrice}</div>
                        <div class="num-box">
                            <button class="down-btn" goodsid="${item.goodsId}">-</button>
                            <div>
                                <span id="num" class="p-num" goodsid="${item.goodsId}">${item.goodsCount}</span>
                            </div>
                            <button class="up-btn"  goodsid="${item.goodsId}">+</button>
                        </div>
                    </td>
                    <td class="action">
                        <button class="delate-btn" goodsid="${item.goodsId}">删除</button>
                    </td >
                </tr >
            </tbody >
        </table >
                `;
        })
        $('.od-inner').html(str)

        let obtn = document.getElementsByTagName("button");
        let onum = document.getElementsByClassName("p-num");
        let ototal = document.getElementsByClassName("l-total")
        let oaddnum = document.querySelector("#total-goodsnum");
        let oaddprice = document.querySelector("#total-pricenum");
        let update = new ShopCar(obtn, onum, oaddnum, ototal, oaddprice);
    }
    );
}
